package com.yanqu.road.server.logic.activity.common.condition.union;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.CommonActivityUnionRiseRankArgs;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.common.CommonActivityData;
import com.yanqu.road.server.logic.activity.common.condition.BaseCommonActivityUnionRankCondition;
import com.yanqu.road.server.manger.activity.CommonActivityMgr;
import com.yanqu.road.server.manger.activity.CommonActivityRankMgr;

public class CommonActivityScoreUnionRankCondition extends BaseCommonActivityUnionRankCondition {

    public CommonActivityScoreUnionRankCondition(GamePlayer player, CommonActivityData commonActivityData, ActivityConditionInfo conditionInfo) {
        super(player, commonActivityData, conditionInfo);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.CommonActivityScoreRiseRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.CommonActivityScoreRiseRank.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return false;
    }

    @Override
    public void initDefaultValue() {
        setUnionRankActivityDefaultValue(player.getUserInfo().getUnionUid(), UnionRiseRankArgs.NOTIFY_TYPE_NORMAL);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        CommonActivityUnionRiseRankArgs args = (CommonActivityUnionRiseRankArgs) object;
        if(null != args) {
            ActivityInfo commonActivityInfo = CommonActivityMgr.getInTimeCommonActivityInfo(activityData.getActivityId());
            if(null != commonActivityInfo && commonActivityInfo.getChildType() == args.getActivityType()) {
                setUnionRankActivityValue(getValue().add(args.getValue()), args.getUnionUid(), args.getType());
                if (UnionRiseRankArgs.NOTIFY_TYPE_DELETE == args.getType()) {//解散商会
                    CommonActivityRankMgr.removeUnionActivityRank(activityData.getActivityId(), args.getUnionUid());
                }
            }
        }
    }
}
